public class Queue implements IQueue {

    static class ListNode {
        public ListNode next;
        public ListNode prev;
        public int val;

        public ListNode(int val) {
            this.val = val;
        }
    }


    public ListNode first;
    public ListNode last;
    public int usedSize;

    //尾插
    public void offer(int data) {

        ListNode newNode = new ListNode(data);

        if(first == null) {
            first = newNode;
            last = newNode;
        } else {
            //尾插
            last.next = newNode;
            newNode.prev = last;
            last = newNode;
        }
        this.usedSize++;
    }


    //删除头结点
    public int poll() {

        if(isEmpty()) {
            return -1;
        }

        int val = first.val;

        if(first.next == null) {
            //如果只有一个结点
            first = null;
            last = null;
        } else {
            first = first.next;
            first.prev = null;
        }
        this.usedSize--;

        return val;
    }

    //获取头结点元素
    public int peek() {
        if(isEmpty()) {
            return -1;
        } else {
            return first.val;
        }

    }

    public int size() {
        return this.usedSize;
    }

    public boolean isEmpty() {
        return usedSize == 0;
    }






}
